import { z } from "zod"; import { validate } from "#server/utils/validation"; import { updateProject, getProject } from "../../service/projects"; const updateSchema = z.object({ name: z.string().min(1, "项目名不能为空").max(100).optional(), tags: z.string().max(500).nullable().optional(), description: z.string().max(1000).nullable().optional(), path: z.string().max(500).nullable().optional(), }); export default defineWrappedResponseHandler(async (event) => { const id = parseInt(getRouterParam(event, "id") || ""); if (!id || isNaN(id)) { throw createError({ statusCode: 400, statusMessage: "无效的项目 ID" }); } const existing = await getProject(id); if (!existing) { throw createError({ statusCode: 404, statusMessage: "项目不存在" }); } const body = await readBody(event); const data = validate(updateSchema, body); await updateProject(id, data); return R.success(null); });